<?php
include_once('common/header.php');
if($AppUI->id <= 0 || (isset($_SESSION['slideshow']) && (($_SESSION['slideshow']&1<<1) == 0))) {
	$this->_redirect(HOST_BACKEND);
}
$intType		= $objRequest->getParam('ptype', 0);
$intForm		= $objRequest->getParam('pform', 0);
$intAlbumId		= $objRequest->getParam('palbumid', 0);
$strAlbumName	= $objRequest->getParam('pal_name', '');
$strName		= $objRequest->getParam('pname', '');
$oFile			= $_FILES['pimage'];
$intError		= 0;
if($intForm == 0) {		
	$strImage		= '';
	$strThumb		= '';
	if($intError == 0 && isset($oFile)) {
		$arrImage	= PhungTK_Upload::uploadProduct($oFile);
		if($arrImage['error'] == 0) {
			$strImage	= $arrImage['path'];
		}else {
			$intError 	= 5;
		}
	}	
	if($intError == 0) {
		if(isset($_SESSION['proupost'])) unset($_SESSION['proupost']);
		if(isset($_SESSION['prouerr'])) unset($_SESSION['prouerr']);		
		$objProduct 	= new Product();
		$intError	= $objProduct->addAlbum($AppUI->id, PhungTK_Function::stripTags($strAlbumName,-2), $strImage, PhungTK_Function::stripTags($strName,-2), $intType);
		if($intError == 0) {
			PhungTK_Function::setMsg($arrMessage[7]);
			$this->_redirect(HOST_BACKEND . 'product/album');
		}
	}
	if($intError > 0) {
		$_SESSION['proupost']	= $objRequest->getParams();
		$_SESSION['prouerr']	= $arrError[$intError];
		$this->_redirect(HOST_BACKEND . 'product/upload');
	}
}elseif($intForm == 1) {
	$strImage		= '';
	$strThumb		= '';
	if($intError == 0 && isset($oFile)) {
		$arrImage	= PhungTK_Upload::uploadProduct($oFile);
		if($arrImage['error'] == 0) {
			$strImage	= $arrImage['path'];
		}else {
			$intError 	= 5;
		}
	}
	if($intError == 0) {
		if(isset($_SESSION['proupost'])) unset($_SESSION['proupost']);
		if(isset($_SESSION['prouerr'])) unset($_SESSION['prouerr']);		
		$objProduct 	= new Product();
		$intError		= $objProduct->addImage($AppUI->id, $intAlbumId, $strImage, PhungTK_Function::stripTags($strName,-2));
		if($intError == 0) {
			PhungTK_Function::setMsg($arrMessage[9]);			
		}
	}
	if($intError > 0) {
		$_SESSION['proupost']	= $objRequest->getParams();
		$_SESSION['prouerr']	= $arrError[$intError];		
	}
	$this->_redirect(HOST_BACKEND . 'product/upload?form='. $intForm . '&albumid=' . $intAlbumId . '&type=' . $intType);
}elseif($intForm == 2) {
	if($intError == 0) {
		if(isset($_SESSION['proupost'])) unset($_SESSION['proupost']);
		if(isset($_SESSION['prouerr'])) unset($_SESSION['prouerr']);		
		$objProduct 	= new Product();
		$intError		= $objProduct->updateAlbum($AppUI->id, $intAlbumId, PhungTK_Function::stripTags($strAlbumName,-2), $intType);
		if($intError == 0) {
			PhungTK_Function::setMsg($arrMessage[8]);
			$this->_redirect(HOST_BACKEND . 'product/album');
		}
	}
	if($intError > 0) {
		$_SESSION['proupost']	= $objRequest->getParams();
		$_SESSION['prouerr']	= $arrError[$intError];
		$this->_redirect(HOST_BACKEND . 'product/upload?type='. $intType . '&albumid=' . $intAlbumId . '&form=' . $intForm);
	}
}
?>